Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add toArray and toList functions to Collection #30

Merged

Conversation

Bl00D4NGEL
Copy link
Collaborator

As a user of the the library I sometimes find myself wanting to use the collection as an array/list to, for example, sort it.

This usually will look like this:

$collection = new Collection([1,2,3]);
$array = iterator_to_array($collection);
$sorted = usort($array, static fn (int $valueA, int $valueB) => $valueA <=> $valueB);

Or in a case where I want to use the collection as a list of items to, for example, expose it in a symfony controller and want to make sure that it's returned as a list instead of a potential associative array:

$collection = new Collection([1,2,3]);
$list = array_values(iterator_to_array($collection));
return $this->json($list);

Which, in both cases, the library could do internally which is why this PR introduces these functions

@Bl00D4NGEL Bl00D4NGEL merged commit 9b67d79 into geekcell:main Apr 24, 2024
1 check passed
@Bl00D4NGEL Bl00D4NGEL deleted the feat/add-array-functions-to-collection branch April 24, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants